<script setup>
import axios from 'axios'
import { onMounted, ref } from 'vue'
import { useRoute , useRouter} from 'vue-router';

const route = useRoute()
const router = useRouter()
const detailInfo = ref({})

onMounted(async () => {
  let id = route.query.id
  console.log('从路由中获取到id=====', id);
  // let res = await axios.get('http://127.0.0.1:3000/api/detail?id=' + id)
  // detailInfo.value =  res.data

  detailInfo.value = {
    id:1,
    name:'xiaoming',
    title:'来验证下苹果的神奇功效',
    info:'介绍下详情的自己----------------',
    path:'/index/recommend',
    count:200,
    image:'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQFAh_XeIAKli9PtOldvm0iTWEdIyEdchppGR22elZ-WhZoqDtinfETB5LZXA&s'
  }
})

function back(){
  router.push('/index/recommend')
}
</script>

<template>
  <div class="detail">
    <div class="back">
      <span @click="back">返回列表</span>
    </div>
    <div class="img">
      <img :src="detailInfo.image" alt=""/>
    </div>
    <div class="item">
      <div class="title">{{ detailInfo.title }}</div>
      <div class="info">{{ detailInfo.info }}</div>
    </div>
  </div>
</template>

<style scoped>
.back {
  padding: 20px;
  display: flex;
  align-items: center;
}
.img {
  width: 100%;
  background-color: #F7F7F7;
  text-align: center;
  overflow: hidden;
}
.img img {
  width: 80%;
  margin: auto;
}
.item {
  padding: 10px;
}
.title{
  font-weight: bold;
}
</style>